//
//  CheekMessageAlertView.m
//  CheekiOS
//
//  Created by mac on 2017/7/12.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "CheekMessageAlertView.h"

@interface CheekMessageAlertView ()

@property (nonatomic, strong)UILabel *titleLab;
@property (nonatomic, strong)UILabel *textLab;
@property (nonatomic, strong)UIButton *determineBtn;

@end

@implementation CheekMessageAlertView

- (instancetype)init {
    self = [super init];
    if (self) {
        [self addSubViews];
        
        
        self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.3f];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubViews];
        
        
        self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.3f];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self addSubViews];
        
        self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.3f];

        
    }
    return self;
}
-(void)addSubViews{
    UIView *BgView = [[UIView alloc]init];
    BgView.backgroundColor = [UIColor whiteColor];
    BgView.frame = CGRectMake(25, self.centerY-130*SCREEN_WIDTH_RATIO47, KScreenWidth-50, 130*SCREEN_WIDTH_RATIO47);
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:  BgView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight |UIRectCornerBottomRight | UIRectCornerBottomLeft cornerRadii:CGSizeMake(10, 10)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame =   BgView.bounds;
    maskLayer.path = maskPath.CGPath;
    BgView.layer.mask = maskLayer;
    [self addSubview:BgView];
    
    _titleLab = [[UILabel alloc] init];
    _titleLab.textColor = [UIColor blackColor];
    _titleLab.font = FontP(17);
    _titleLab.textAlignment = NSTextAlignmentCenter;
    _titleLab.frame = CGRectMake(0, 10*SCREEN_WIDTH_RATIO47, BgView.width, 25*SCREEN_WIDTH_RATIO47);
    [BgView addSubview:_titleLab];
    
    _textLab = [[UILabel alloc] initWithFrame:CGRectMake(0, _titleLab.bottom+7.5*SCREEN_WIDTH_RATIO47, BgView.width, 20*SCREEN_WIDTH_RATIO47)];
    _textLab.textColor = [UIColor blackColor];
    _textLab.font = FontP(12);
    _textLab.textAlignment = NSTextAlignmentCenter;
    [BgView addSubview:_textLab];

    CGFloat btnW = (BgView.width-55*SCREEN_WIDTH_RATIO47)/2;
    
    UIButton *calcanbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    calcanbtn.frame = CGRectMake(20*SCREEN_WIDTH_RATIO47, _textLab.bottom+14*SCREEN_WIDTH_RATIO47, btnW, 45*SCREEN_WIDTH_RATIO47);
    calcanbtn.layer.cornerRadius = 5;
    calcanbtn.layer.masksToBounds = YES;
    calcanbtn.backgroundColor = RGB(246, 246, 246);
    calcanbtn.titleLabel.font = FontP(15);
    
    
    [calcanbtn addTarget:self action:@selector(removeBtn:) forControlEvents:UIControlEventTouchUpInside];
    [calcanbtn setTitle:@"取消" forState:UIControlStateNormal];
    [calcanbtn setTitleColor:ColorI(0x2e353f) forState:UIControlStateNormal];
    calcanbtn.tag = 0;
    [BgView addSubview:calcanbtn];
    
    
    _determineBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _determineBtn.frame = CGRectMake(calcanbtn.right+15*SCREEN_WIDTH_RATIO47, _textLab.bottom+14*SCREEN_WIDTH_RATIO47, btnW, 45*SCREEN_WIDTH_RATIO47);
    _determineBtn.layer.cornerRadius = 5;
    _determineBtn.layer.masksToBounds = YES;
    _determineBtn.backgroundColor = Colorbackground;
    _determineBtn.titleLabel.font = FontP(15);
    _determineBtn.tag = 1;
    [_determineBtn setTitleColor:ColorI(0x2e353f) forState:UIControlStateNormal];

    [_determineBtn addTarget:self action:@selector(determine:) forControlEvents:UIControlEventTouchUpInside];

    [BgView addSubview:_determineBtn];
    
}

-(void)CheekAlertTitle:(NSString *)title text:(NSString *)text determineTitle:(NSString *)determineTitle determineBtnTage:(NSInteger )determineBtnTage{
    [_determineBtn setTitle:determineTitle forState:UIControlStateNormal];
    _determineBtn.tag = determineBtnTage;
    _titleLab.text = title;
    _textLab.text = text;
}

- (void)removeBtn:(UIButton *)sender{

    if ([self.delegate respondsToSelector:@selector(removeBtn:)]) {
        [self.delegate removeBtn:sender];
    }
    
}
- (void)determine:(UIButton *)sender{
    if ([self.delegate respondsToSelector:@selector(determine:)]) {
        [self.delegate determine:sender];
    }
}



@end
